import fred
import sys,os
import q
sys.path.append("/home/vvishwa/python")
conn = q.conn('localhost', 5000)
test = conn('1+1')
print test
#conn('liborUSD3MHistory:([]date:1986.01.01T 1986.01.02T;rate:8.0 8.0)')
conn('liborUSD3MHistory:([]date:`datetime$() ;rate:`float$())')
conn('liborUSD3MHistory1:`date`rate!(2012-12-13;123.00)')
fred.key('429d7dba943722523e1329dfaefd3b2a')
fred_data = fred.observations('USD3MTD156N')

data = fred_data.values()
nv = data[8]
for da in nv:
#    print da['date'], '=', da['value']
    try:
        newrecord = '(%sT;%f)' % (str(da['date']).replace('-','.'), float(da['value']))
        insertcommand = '`%s insert %s' % ('liborUSD3MHistory', newrecord)
        conn(insertcommand)
    except ValueError:
        print 'Skipping'

test = conn('select from liborUSD3MHistory')
print test
conn('`:liboxUSD3MHistory.qdata set liborUSD3MHistory')
